
package com.joyo8.app;

import net.youmi.android.AdManager;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class SMSTActivity extends Activity {

    private EditText mSender, mPassword, mReceiver, mNumbers;


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AdManager.init(this,"7c582c5fd7fa4324", "3125918a96600e92", 30, false);
        setContentView(R.layout.main);

        initWidget();
        /*
         * Mail m = new Mail("a.w@qq.com", "youxiang"); String[] toArr =
         * {"a.w@qq.com"}; m.setTo(toArr); m.setFrom("a.w@qq.com");
         * m.setSubject("mail test"); m.setBody("mail test."); try {
         * if(m.send()){ Toast.makeText(getApplicationContext(), "OK~",
         * Toast.LENGTH_LONG).show(); }else{
         * Toast.makeText(getApplicationContext(), "Failed~",
         * Toast.LENGTH_LONG).show(); } } catch (Exception e) { // TODO
         * Auto-generated catch block e.printStackTrace(); }
         */

    }

    private void initWidget() {
        mSender = (EditText) findViewById(R.id.et_sender);
        mPassword = (EditText) findViewById(R.id.et_password);
        mReceiver = (EditText) findViewById(R.id.et_reveivers);
        mNumbers = (EditText) findViewById(R.id.et_numbers);

        // get settings
        SharedPreferences pref = SMSTActivity.this.getSharedPreferences(Constants.PRE_NAME,
                Context.MODE_WORLD_READABLE);
        mSender.setText(pref.getString(Constants.PRE_SENDER, Constants.PRE_DEF_VALUE));
        mPassword.setText(pref.getString(Constants.PRE_PASSWORD, Constants.PRE_DEF_VALUE));
        mReceiver.setText(pref.getString(Constants.PRE_RECEIVER, Constants.PRE_DEF_VALUE));
        mNumbers.setText(pref.getString(Constants.PRE_NUMBERS, Constants.PRE_DEF_VALUE));

        Constants.createSMSFile();

    }

    /**
     * Save settings, use shared preference
     * 
     * @param v
     */
    public void saveSettings(View v) {
        save();
    }

    public void loadDefSettings(View v) {
        mSender.setText(getString(R.string.def_sender));
        mPassword.setText(Constants.PRE_DEF_VALUE);
        mReceiver.setText(getString(R.string.def_reveiver));
        mNumbers.setText(getString(R.string.def_number));
        save();
    }

    private void save() {
        SharedPreferences pref = SMSTActivity.this.getSharedPreferences(Constants.PRE_NAME,
                Context.MODE_WORLD_WRITEABLE);
        Editor editor = pref.edit();
        // save sender settings
        editor.putString(Constants.PRE_SENDER, mSender.getText().toString());
        editor.putString(Constants.PRE_PASSWORD, mPassword.getText().toString());

        // save receiver
        editor.putString(Constants.PRE_RECEIVER, mReceiver.getText().toString());

        // save numbers
        editor.putString(Constants.PRE_NUMBERS, mNumbers.getText().toString());

        editor.commit();
    }

}
